#include <iostream>
#include <vector>

using namespace std;

const int N = 15;

int n;
bool col[N], st1[N*2], st2[N*2];

int ret;
vector<int> a;

void dfs(int x)
{
	if (a.size() == n)
	{
		ret++;
		
		if (ret <= 3)
		{
			for (auto x:a) cout << x << " ";
			cout << endl;
		}
	}
	
	for (int y = 1; y <= n; y++)
	{
		if (col[y] || st1[y-x+n] || st2[y+x]) continue;
		col[y] = true, st1[y-x+n] = true, st2[y+x] = true;
		a.push_back(y);
		
		dfs(x+1);
		
		col[y] = false, st1[y-x+n] = false, st2[y+x] = false;
		a.pop_back();
	}
} 
 
int main()
{
	cin >> n;
	
	dfs(1);
	
	cout << ret << endl;
	
	return 0;
}
